package com.jz.netthings.system.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jz.netthings.annotation.AdscmLogger;
import com.jz.netthings.bean.system.JyCode;
import com.jz.netthings.bean.system.JyUser;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.security.utils.Token;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.system.mapper.mysql.JyCodeMapper;
import com.jz.netthings.system.service.JyCodeService;
import com.jz.netthings.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yyy
 * @ClassName AdscmSystemController
 * @Description 用户管理Controller
 * @date 2018/8/1 17:34
 */
@RestController
@RequestMapping("/adscm/system/code")
public class AdscmCodeController {
      @Autowired
      JyCodeMapper jyCodeMapper;
      @Autowired
    JyCodeService jyCodeService;
    @RequestMapping("queryCoedByType/{type}")
    public SimpleCoreResponse queryCoedByType(@PathVariable String type) throws AdscmSystemException {
        List<JyCode> jyCodeByCodeType = jyCodeMapper.getJyCodeByCodeType(type);
        return new SimpleCoreResponse("200", "查询成功", jyCodeByCodeType);
    }
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody JyCode jyCode) throws AdscmSystemException {
        boolean insert = jyCodeService.insert(jyCode);
        return new SimpleCoreResponse("200", "新增成功", insert);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody JyCode jyCode) throws AdscmSystemException {
        boolean insert = jyCodeService.updateById(jyCode);
        return new SimpleCoreResponse("200", "修改成功", insert);
    }
    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id) throws AdscmSystemException {
        boolean b = jyCodeService.deleteById(Long.valueOf(id));
        return new SimpleCoreResponse("200", "新增成功", b);
    }
    @RequestMapping("selectByCodeType/{id}")
    public SimpleCoreResponse selectByCodeType(@PathVariable Integer id) throws AdscmSystemException {
        Wrapper<JyCode> jyCodeWrapper =new EntityWrapper<>();
        jyCodeWrapper.eq("type",id);
        List<JyCode> jyCodes = jyCodeService.selectList(jyCodeWrapper);
        return new SimpleCoreResponse("200", "新增成功", jyCodes);
    }


}
